package org.example.acm;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class InputAssociateSolution {

    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String sentence = br.readLine();
            String prefix = br.readLine();
            sentence = sentence.replaceAll("[^a-zA-Z]", " ");
            String[] words = sentence.split("\\s+");
            InputAssociateSolution solution = new InputAssociateSolution();
            solution.doFind(words, prefix);
        } catch (Exception e) {
            System.out.println(e);
        }

    }

    public void doFind(String[] words, String prefix) {
        Trie trie = new Trie();
        for (String word: words) {
            trie.insert(word);
        }
        List<String> res = trie.findByPrefix(prefix);
        if (res.isEmpty()) {
            System.out.println(prefix);
        } else {
            System.out.println(String.join(" ", res));
        }
    }

    public static void main2(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            String sentence = br.readLine();
            String prefix = br.readLine();
            sentence = sentence.replaceAll("[^a-zA-Z]", " ");
            Set<String> treeSet = new TreeSet<>();
            String[] words = sentence.split("\\s+");
            for (String word: words) {
                treeSet.add(word);
            }
            StringBuilder sb = new StringBuilder();
            for (String word: treeSet) {
                if (word.startsWith(prefix)) {
                    sb.append(word).append(" ");
                }
            }
            if (sb.length() > 0) {
                System.out.println(sb.toString().trim());
            } else {
                System.out.println(prefix);
            }

        } catch (Exception e) {
            System.out.println(e);
        }
    }

    class Trie {
        private Trie[] children;
        private boolean isEnd;

        public Trie() {
            this.children = new Trie[52];
        }

        public void insert(String word) {
            Trie node = this;
            for (int i=0;i<word.length();i++) {
                int index = findIndex(word.charAt(i));
                if (node.children[index] == null) {
                    node.children[index] = new Trie();
                }
                node = node.children[index];
            }
            node.isEnd = true;
        }

        public int findIndex(char c) {
            if (c>='a' && c<='z') {
                return c-'a';
            } else {
                return c-'A'+26;
            }
        }

        public List<String> findByPrefix(String prefix) {
            List<String> res = new ArrayList<>();
            Trie node = this;
            for (int i=0;i<prefix.length();i++) {
                int index = findIndex(prefix.charAt(i));
                if (node.children[index] == null) {
                    return res;
                }
                node = node.children[index];
            }
            dfsFindFromNode(node, prefix, res);
            return res;
        }

        private void dfsFindFromNode(Trie node, String prefix, List<String> res) {
            if (node == null) {
                return;
            }
            if (node.isEnd) {
                res.add(prefix);
            }
            for (char i='a';i<='z';i++) {
                int index = findIndex(i);
                if (node.children[index] != null) {
                    dfsFindFromNode(node.children[index], prefix+i, res);
                }
            }
            for (char i='A';i<='Z';i++) {
                int index = findIndex(i);
                if (node.children[index] != null) {
                    dfsFindFromNode(node.children[index], prefix+i, res);
                }
            }
        }
    }
}
